
package control;

import dao.TweetDao;
import entity.Tweet;
import entity.User;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author AnBoCa
 */
public class ComposeTweetBean {

    private String text;
    private Long date;
    private String authorName;
    private Long authorID;
    private List<String> hashTags;
    private List<String> tags;
    private List<String> webPage;
    private List<String> image;
    private List<String> video;
    
    public ComposeTweetBean() {
    }
    
    public void composeTweet(){
        //revisar la session
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        User user=null;
        if (session!=null)
            user=(User)session.getAttribute("user");
        if (user!=null){
            TweetDao tweetDao=new TweetDao();
            Tweet tweet=new Tweet();
            tweet.setText(text);
            tweet.setAuthorID(user.getID());
            tweet.setAuthorName(user.getUserName());
            //tweet.setDate();
            tweet.setVideo(video);
            tweet.setWebPage(webPage);
            tweet.setImage(image);
            System.out.println(text + "" + authorID);
            tweetDao.insert(tweet, null, null);
        }else{
            FacesContext fc=FacesContext.getCurrentInstance();
            try {
                fc.getExternalContext().redirect(fc.getExternalContext().getRequestContextPath()+"/login.xhtml");
            } catch (IOException ex) {
                Logger.getLogger(ComposeTweetBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public Long getAuthorID() {
        return authorID;
    }

    public void setAuthorID(Long authorID) {
        this.authorID = authorID;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public Long getDate() {
        return date;
    }

    public void setDate(Long date) {
        this.date = date;
    }

    public List<String> getHashTags() {
        return hashTags;
    }

    public void setHashTags(List<String> hashTags) {
        this.hashTags = hashTags;
    }

    public List<String> getImage() {
        return image;
    }

    public void setImage(List<String> image) {
        this.image = image;
    }

    public List<String> getTags() {
        return tags;
    }

    public void setTags(List<String> tags) {
        this.tags = tags;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public List<String> getVideo() {
        return video;
    }

    public void setVideo(List<String> video) {
        this.video = video;
    }

    public List<String> getWebPage() {
        return webPage;
    }

    public void setWebPage(List<String> webPage) {
        this.webPage = webPage;
    }
    
}
